home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / WE_30D.ZIP / WEEXTSRC.ZI_ / WE_EXT.C < prev    next >
C/C++ Source or Header  |  1993-07-30  |  13KB  |  424 lines

  1. /*-------------------------------------------------------------------------*\
  2.  |                                                                         |
  3.  |                                                                         |
  4.  |  WE_EXT.C - A Sample DLL Extension Processor for WinEdit                |
  5.  |                                                                         |
  6.  |                                                                         |
  7. \*-------------------------------------------------------------------------*/
  8. #define STRICT
  9. #define _WINDLL
  10. #include <windows.h>
  11. #include "we_ext.h"
  12. #include "private.h"
  13. #include <string.h>
  14.  
  15. #define NOREF(a)  {a=a;}
  16.  
  17. HMENU hTrackMenu;
  18. BOOL bWait=TRUE;
  19. BOOL bCapture=TRUE;
  20. char szCommand[256];
  21.  
  22. /*
  23.  * JLD-12/9/92 Added this to setup the default GREP string, which recurs if
  24.  * no work is under the cursor.  See line 204.
  25.  */
  26.  
  27. char GLOB_GrepCmd[256] = {"tee.com fgrep.com -M %s *.c"};
  28.  
  29. #ifndef WIN32
  30. #define APIENTRY WINAPI
  31. #endif
  32.  
  33. #if !defined(LONG2POINT)
  34. #define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), (pt).y=(SHORT)HIWORD(l))
  35. #endif
  36.  
  37. /*-------------------------------------------------------------------------*\
  38.  |                                                                         |
  39.  |  Function:   WE_ExtensionProc                                           |
  40.  |                                                                         |
  41.  |  Purpose:    WinEdit calls this function with the WEN_* messages and    |
  42.  |              whenever a user-defined menu item or accelerator is        |
  43.  |              accessed.                                                  |
  44.  |                                                                         |
  45.  |  Parameters: HWND hWnd   - WinEdit's window handle                      |
  46.  |                                                                         |
  47.  |              UINT wParam - Message ID.  If wParam is >= WE_EXTFIRST,    |
  48.  |                            the DLL is being requested to perform the    |
  49.  |                            user-defined action.                         |
  50.  |                                                                         |
  51. \*-------------------------------------------------------------------------*/
  52. UINT APIENTRY WE_ExtensionProc(HWND hWnd,     /* WinEdit's window handle */
  53.                                  HANDLE hInst,  /* instance identifier     */
  54.                                  UINT wParam,   /* command ID              */
  55.                                  LONG lParam)   /* additional information  */
  56.    {
  57.  
  58.    switch (wParam)
  59.       {
  60.  
  61.       case WEN_LOADMENU:
  62.  
  63.          /*  This is the menu WinEdit will display when there
  64.           *  is at least one document window open.  Return NULL
  65.           *  to use the default WinEdit menu.
  66.           *
  67.           */
  68.  
  69.          return (UINT)LoadMenu(hInst, "MyMenu");
  70.          break;
  71.  
  72.       case WEN_LOADSHORTMENU:
  73.  
  74.          /*  this is the menu WinEdit will display when there
  75.              *  are no document windows open.  Return NULL
  76.              *  to use the default WinEdit menu.
  77.              *
  78.              */
  79.    
  80.             return (UINT)LoadMenu(hInst, "MyShortMenu");
  81.             return 0;
  82.             break;
  83.    
  84.       case WEN_LOADACCELS:
  85.  
  86.          /*  To add accelerators for new commands, load your
  87.           *  own accelerator table here.  Return NULL to
  88.           *  use the default WinEdit accelerators.
  89.           *
  90.           */
  91.  
  92.          return (UINT)LoadAccelerators (hInst,"MyAccels");
  93.          break;
  94.  
  95.       case WEN_GETWINDOWMENU:
  96.  
  97.          /*  WinEdit needs the handle of the submenu to
  98.           *  append MDI document names to.  The hWnd parameter
  99.           *  is used to send the handle to the main menu.
  100.           *  This message will not be sent if you return
  101.           *  NULL to the WEN_LOADMENU message.
  102.           */
  103.          return (UINT)GetSubMenu ((HMENU)hWnd, WINDOWMENU);
  104.          break;
  105.  
  106.       case WEN_RBUTTONDOWNS:
  107.          edHelpKeyWord(hWnd);
  108.          break;
  109.  
  110.       case WEN_RBUTTONDOWN:
  111.  
  112.          if (!hTrackMenu)
  113.             {
  114.  
  115.             hTrackMenu = CreatePopupMenu();
  116.             if (!hTrackMenu)
  117.                break;
  118.  
  119.  /* JLD 12/9/92 - Changed these labels to the Ctrl-V,X,Z, etc. which matches the 
  120.   *               current pull-down labels.
  121.   *               Also changed F3 to Previous error, F4 to next error, which seems
  122.   *               more consistent.  I left Re-Do as Ctrl-Backspace. 
  123.   *               Added Close to this menu.
  124.   *               Added Ctrl L as a synonym for Ctrl-F5.  (similar to Wordstar)
  125.   */ 
  126.                
  127.             AppendMenu(hTrackMenu,MF_STRING,IDM_FILEOPEN,"&Open...\tF3");
  128.             AppendMenu(hTrackMenu,MF_STRING,IDM_FILESAVE,"&Save\tF2");                 
  129.             AppendMenu(hTrackMenu,MF_STRING,IDM_WINDOWCLOSE,"&Close\tCtrl+F4");                
  130.             AppendMenu(hTrackMenu,MF_STRING,IDM_FILEPRINT,"&Print\tF9");                
  131.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  132.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITUNDO,"&Undo\tCtrl+Z");           
  133.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITREDO,"&Redo\tCtrl+BkSp");          
  134.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  135.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITCUT,"Cu&t\tCtrl+X");     
  136.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITCOPY,"&Copy\tCtrl+C");            
  137.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITPASTE,"&Paste\tCtrl+V");          
  138.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  139.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHFIND,"&Find...\tF5");              
  140.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHNEXT,"&Repeat Last Find\tCtrl+F5|L");
  141.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHCHANGE,"&Change...\tF6");            
  142.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  143.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHPREVERR,"&Previous Error\tShift+F3");    
  144.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHNEXTERR,"&Next Error\tShift+F4");
  145.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  146.             AppendMenu(hTrackMenu,MF_STRING,IDM_HELPKEYWORDS,"&Key Word Help\tShift+F1");  
  147.             }
  148.             
  149.          if (hTrackMenu)
  150.             {
  151.             POINT pt;
  152. #ifdef WIN32
  153.             LONG2POINT((LPARAM)lParam,pt);
  154. #else
  155.             pt = MAKEPOINT(lParam);
  156. #endif
  157.             TrackPopupMenu(hTrackMenu,0,pt.x-10,pt.y-6,0,hWnd,0L);
  158.             }
  159.             
  160.          return TRUE;   
  161.          break;
  162.  
  163.       case WEN_END:
  164.  
  165.          /*  WinEdit is shutting down.  Do any clean-up processing
  166.           *  here.
  167.           */
  168.          if (hTrackMenu)
  169.             {
  170.             DestroyMenu(hTrackMenu);
  171.             hTrackMenu = (HMENU)NULL;
  172.             }
  173.          return TRUE;
  174.          break;
  175.  
  176.       case WEN_INITMENU:
  177.  
  178.          /*  This message is sent before showing any drop down
  179.           *  menu items.  Respond by setting any checkmarks,
  180.           *  graying any inapplicable items, etc.
  181.           *
  182.           */
  183.          return InitMenu(hWnd);
  184.          break;
  185.  
  186.  
  187.       /*  You can define your own commands in the range
  188.        *  WE_EXTFIRST to WE_EXTLAST that can be attached to
  189.        *  menu items or accelerators.
  190.        */
  191.  
  192.       case EXT_GREP:
  193.          {
  194.          char szWord[64];
  195.          edEditGetCurrentWord(hWnd,szWord,63);
  196.          if (szWord[0])
  197.             wsprintf(szCommand,"tee.com fgrep.com -M %s *.c",(LPSTR)szWord);
  198.          else
  199.             wsprintf(szCommand,GLOB_GrepCmd);  /* JLD 12/9/92 see beginning of file */
  200.  
  201. /* JLD 12/9/92 this *remembers* the last string if no word is selected */
  202.             
  203.          if (DialogBox(hInst,"CommandBox",hWnd,CommandDlgProc))
  204.             edRunCommand(hWnd, bWait, bCapture, szCommand);
  205.          strcpy(GLOB_GrepCmd,szCommand);  /* JLD 12/9/92 save current into the GLOB var */
  206.          return TRUE;
  207.          break;
  208.          }
  209. /* JLD 12/9/92 the following now provide braces for if and for, similar to t